﻿////自定义叠加层
//function customOverlay(point, name, map) {
//    this.point_ = point;
//    this.name_ = name;
//    this.map_ = map;
//    this.div = null;
//    this.setMap(map);
//}

//customOverlay.prototype = new BMap.OverlayView();

//customOverlay.prototype.onAdd = function() {
//    // 创建一个div，其中包含了当前文字
//    var div = document.createElement("div");
//    div.style.border = "solid blue 2px";
//    //div.style.backgroundColor = "white";
//    div.style.backgroundColor = "white";
//    div.style.fontSize = "11.5px";
//    div.style.fontFamily = '"Times New Roman\", Times, serif';
//    div.style.width = "300";

//    if (!browser.isNS) {
//        div.style.filter = "alpha(opacity=70)";
//    } else {
//        div.style.opacity = "0.7";
//        div.style._moz_opacity = "0.7";
//    }
//    var span = document.createElement("span");
//    var text = document.createTextNode(this.name_);
//    span.appendChild(text);
//    div.appendChild(span);
//    div.style.borderStyle = "none";
//    div.style.borderWidth = "0px";
//    div.style.position = "absolute";
//    this.div = div;
//    //var me = this;
//    var panes = this.getPanes();
//    panes.overlayImage.appendChild(div);
//}

//customOverlay.prototype.draw = function() {
//    var overlayProjection = this.getProjection();
//    var center = overlayProjection.fromLatLngToDivPixel(this.point_);
//    var div = this.div;
//    div.style.left = center.x + "px";
//    div.style.top = center.y + "px";
//    div.style.width = "100px";
//    div.style.height = "8px";
//}

//customOverlay.prototype.setPosition = function(latlng) {
//    this.point_ = latlng;
//    this.draw();
//}

//customOverlay.prototype.onRemove = function() {
//    this.div.parentNode.removeChild(this.div);
//    this.div = null;
//}



//自定义叠加层
function customOverlay(point, text, overText, map) {
    this.point = point;
    this.text = text;
    this.overText = overText;
    this.div = null;
    //    this.setMap(map);
}

customOverlay.prototype = new BMap.Overlay();

customOverlay.prototype.onAdd = function () {

    var div = this._div = document.createElement("div");
    div.style.position = "absolute";
    //div.style.zIndex = BMap.Overlay.getZIndex(this.point.lat());
    div.style.backgroundColor = "#EE5D5B";
    div.style.border = "1px solid #BC3B3A";
    div.style.color = "white";
    div.style.height = "18px";
    div.style.padding = "2px";
    div.style.lineHeight = "18px";
    div.style.whiteSpace = "nowrap";
    div.style.MozUserSelect = "none";
    div.style.fontSize = "12px"
    var span = this._span = document.createElement("span");
    div.appendChild(span);
    span.appendChild(document.createTextNode(this.text));
    var that = this;

    var arrow = this._arrow = document.createElement("div");
    //arrow.style.background = "url(http://map.baidu.com/fwmap/upload/r/map/fwmap/static/house/images/label.png) no-repeat";
    //arrow.style.background = "url(../images/label.png) no-repeat";
    arrow.style.position = "absolute";
    arrow.style.width = "11px";
    arrow.style.height = "10px";
    arrow.style.top = "22px";
    arrow.style.left = "10px";
    arrow.style.overflow = "hidden";
    div.appendChild(arrow);
    div.onmouseover = function () {
        this.style.backgroundColor = "#6BADCA";
        //this.style.borderColor = "#0000ff";
        this.style.borderColor = "#BC3B3A";
        this.getElementsByTagName("span")[0].innerHTML = that.overText;
        arrow.style.backgroundPosition = "0px -20px";
        this.style.zIndex = 999;
    }

    div.onmouseout = function () {
        this.style.backgroundColor = "#EE5D5B";
        this.style.borderColor = "#BC3B3A";
        this.getElementsByTagName("span")[0].innerHTML = that.text;
        arrow.style.backgroundPosition = "0px 0px";
        this.style.zIndex = 0;
    }

    if (!browser.isNS) {
        div.style.filter = "alpha(opacity=70)";
    } else {
        div.style.opacity = "0.7";
        div.style._moz_opacity = "0.7";
    }
    this.div = div;
    var panes = map.getPanes();
    panes.markerPane.appendChild(div);
}

customOverlay.prototype.draw = function () {
    var overlayProjection = map.getMapType().getProjection();
    var pixel = overlayProjection.lngLatToPoint(this.point);
    this.div.style.left = pixel.x + "px";
    this.div.style.top = pixel.y + "px";
    //    this.div.style.width = "100px";
    //    this.div.style.height = "8px";

    //this.div.style.left = pixel.x - parseInt(this._arrow.style.left) + "px";
    //this.div.style.top = pixel.y - 30 + "px";
}

customOverlay.prototype.setPosition = function (latlng) {
    this.point = latlng;
    this.onAdd();

    this.draw();
}

customOverlay.prototype.setText = function (text) {
    this.text = text;
    this.onAdd();
    this.draw();
}
customOverlay.prototype.setOverText = function (overText) {
    this.overText = overText;
    this.onAdd();
    this.draw();
}

customOverlay.prototype.onRemove = function () {
    this.div.parentNode.removeChild(this.div);
    this.onAdd();
    this.div = null;
}	